//editRoleCtrl

app.controller('userEditCtrl', function($element, $scope, $state, rest, user, uploadConf, tipService, $window, $rootScope) {
	$scope.iNowData = angular.copy($scope.ngDialogData, {});
    var token = $window.localStorage.getItem("token");
    
    //自定义方法状态数据
	$scope.methodsStatus = [
	        {
	            "status" : "AVAILABLE",
	            "menuName" : "可用"
	        },
	        {
	            "status" : "FORBID",
	            "menuName" : "禁止"
	        },
	        {
	            "status" : "DELETE",
	            "menuName" : "删除"
	        }
	    ];
	angular.forEach($scope.methodsStatus,function(data,index,array){
		if(data.status == $scope.iNowData.status){
			$scope.itemStatus = data;
		}
	})
    
    $scope.preserveSubmit = function(){
    	//var formData = angular.element("#ajaxForm").serialize();
    	//console.log(formData);
    	var formData = {
    		"id":$scope.iNowData.id,
    		"loginName":$scope.iNowData.loginName,
			"userName":$scope.iNowData.userName,
			"loginPwd":$scope.iNowData.loginPwd,
			"reloginPwd":$scope.iNowData.reloginPwd,
			"mobile":$scope.iNowData.mobile,
			"email":$scope.iNowData.email,
			"jobNumber":$scope.iNowData.jobNumber,
			"status":$scope.itemStatus.status
    	}
    	
    	rest.decoJava({
    		type: 'post',
            url: '/tenancy-sys/admin/user/update', 
            data: JSON.stringify(formData),
            contentType: "application/json; charset=utf-8",
            beforeSend: function(request){
				request.setRequestHeader("token", token); 
			},
            success: function (result) {
            	layer.closeAll('loading');
                if (result) {
                    if ("0000" == result.code) {
						layer.msg(result.message, {
				        	offset:'t',
				        	icon: 1,
							time: 0, //不自动关闭
							btn: ['确定'],
							yes: function(index){
								layer.close(index);
								$scope.closeThisDialog();
						    }
						});
                    } else {
                    	layer.msg(result.message,{
		    				offset:'t'
		    			});
                    }
                }
            }
        })
    };
    
    $scope.hideBtn = function(){
    	$scope.closeThisDialog();
    }
    
});
